package com.theorydance.content_search.util;

import java.util.function.BiFunction;
import java.util.function.Supplier;

/**
 * 单个条件对比，attr与value选用的是同一种类型，因为比较没必要选择不一样的类型比较
 */
public class CompareCondition<T> implements Condition{
	
	Supplier<T> attr;
	T value;
	BiFunction<T, T, Boolean> judge;
	
	/**
	 * 
	 * @param attr 条件左侧
	 * @param value 条件右侧
	 * @param judge 条件判断逻辑
	 */
	public CompareCondition(Supplier<T> attr,T value,BiFunction<T, T, Boolean> judge) {
		this.attr = attr;
		this.value = value;
		this.judge = judge;
	}
	
	@Override
	public boolean apply() {
		return this.judge.apply(this.attr.get(), value);
	}
}
